package com.bdf.ipharma.gui;

import java.awt.Color;
import java.awt.Component;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.awt.geom.AffineTransform;

import javax.swing.JFrame;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.table.JTableHeader;
import javax.swing.table.TableCellRenderer;

import com.bdf.ipharma.model.ProductoModel;

public class JTableExample extends JFrame {

	public static void main(String[] argv) {
		JTableExample myExample = new JTableExample("JTable Example");

	}

	public JTableExample(String title) {
		super(title);
		setSize(150, 150);
		addWindowListener(new WindowAdapter() {
			public void windowClosing(WindowEvent we) {
				dispose();
				System.exit(0);
			}
		});
		init();
		pack();
		setVisible(true);
	}

	private void init() {
		//el new producto es para el dummy del autocompletado.
		JTable productoJTable = new JTable(new ProductoModel(null,null)) {
			private static final long serialVersionUID = 1L;

			public Component prepareRenderer(TableCellRenderer renderer, int Index_row, int Index_col) {
				Component comp = super.prepareRenderer(renderer, Index_row, Index_col);
				comp.setSize(20, 100);

				// even index, selected or not selected
				if (Index_row % 2 == 0 && !isCellSelected(Index_row, Index_col)) {
					// color celestito
					comp.setBackground(new Color(30, 144, 255));
					comp.setForeground(Color.white);
				} else {
					comp.setBackground(Color.white);
					comp.setForeground(new Color(46, 139, 87));
				}
				return comp;
			}
		};
		Dimension dim = new Dimension(20, 1);
		productoJTable.setIntercellSpacing(new Dimension(dim));
		SetRowHight(productoJTable);

		JTableHeader header = productoJTable.getTableHeader();
		header.setBackground(Color.white);

		header.setResizingAllowed(true);
		header.setReorderingAllowed(false);

		productoJTable.setForeground(Color.GRAY);
		productoJTable.setFont(new Font("Tahoma", Font.PLAIN, 18));

		// JTable productoJTable = new JTable(new ProductoModel());

		productoJTable.setShowVerticalLines(false);
		productoJTable.setShowHorizontalLines(false);
		productoJTable.setShowGrid(false);
		
		
		JScrollPane scrollPane = new JScrollPane(productoJTable);
		
		getContentPane().add(scrollPane);
		
		

	}

	public void SetRowHight(JTable table) {
		int height = table.getRowHeight();
		table.setRowHeight(height + 10);
	}

	public void paintComponent(Graphics g) {
		Graphics2D g2 = (Graphics2D) g;
		Font f = new Font("Arial", Font.BOLD, 12);
		g2.setClip(0, 0, 500, 500);
		g2.setColor(new Color(60, 179, 113));
		g2.setFont(f);
		AffineTransform at = new AffineTransform();
		at.setToTranslation(this.getWidth(), this.getHeight());
		g2.transform(at);
		//double radianAngle = (((double) m_degreesRotation) / ((double) 180)) * Math.PI;
		//at.setToRotation(radianAngle);
		g2.transform(at);
		//g2.drawString(this.getText(), 8, -30);
	}
}
